<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\AdminController;
use App\Models\Level as TLevel;
use Illuminate\Http\Request;

class Level extends AdminController{
    
    public function index(Request $req){
        $psize = 15;
        if($req->method() == 'POST'){
            $list = TLevel::orderBy('id')->paginate($psize);
            wxresp(1, ['rows' => $list->items(), 'total' => $list->total()]);
        }
        if (TLevel::count() == 0) TLevel::insert(array('level'=>0,'title'=>'普通代理'));
        return $this->V("index");
    }
    
    public function post(Request $req){
        $id = $req->post('lid');
        $data = [
                'title' => $req->post('title'),
                'bprice' => $req->post('bprice'),
                'uprice' => $req->post('uprice'),
                'rule' => $req->post('rule'),
        ];
        if ($id){
            TLevel::where('id', $id)->update($data);
        }else{
            $data['level'] = TLevel::count();
            $id = TLevel::insertGetId($data);
        }
        wxresp(1);
    }
}